package gui_classes;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JTextArea;
import javax.swing.JButton;

import domain.Orders;

public class OrdersScreen extends DERPBase {
	
	private JTextArea txtrPrescription;
	private JTextArea txtrLabWork;
	private JTextArea txtrFollowUp;
	private JTextArea txtrInstructions;

	/**
	 * Create the panel.
	 */
	public OrdersScreen() {
		setLayout(null);
		setPreferredSize(new Dimension(450,450));
		
		JLabel lblPrescription = new JLabel("Prescription:");
		lblPrescription.setBounds(12, 43, 133, 15);
		add(lblPrescription);
		
		JLabel lblDoctorsOrders = new JLabel("Doctor's Orders");
		lblDoctorsOrders.setBounds(177, 12, 133, 15);
		add(lblDoctorsOrders);
		
		JLabel lblLabWork = new JLabel("Lab Work:");
		lblLabWork.setBounds(12, 126, 151, 15);
		add(lblLabWork);
		
		JLabel lblFollowUpInstructions = new JLabel("Follow Up Instructions");
		lblFollowUpInstructions.setBounds(12, 216, 173, 15);
		add(lblFollowUpInstructions);
		
		txtrPrescription = new JTextArea();
		txtrPrescription.setText("Prescription");
		txtrPrescription.setBounds(37, 59, 360, 62);
		add(txtrPrescription);
		
		txtrLabWork = new JTextArea();
		txtrLabWork.setText("Lab Work");
		txtrLabWork.setBounds(37, 153, 360, 62);
		add(txtrLabWork);
		
		JTextArea txtrFollowUp = new JTextArea();
		txtrFollowUp.setText("Follow Up");
		txtrFollowUp.setBounds(42, 243, 355, 45);
		add(txtrFollowUp);
		
		JButton btnAdd = new JButton("Add");
		btnAdd.setBounds(172, 413, 117, 25);
		btnAdd.addActionListener(new AddListener());
		add(btnAdd);
		
		JLabel lblOtherInstructions = new JLabel("Other Instructions");
		lblOtherInstructions.setBounds(12, 326, 151, 15);
		add(lblOtherInstructions);
		
		txtrInstructions = new JTextArea();
		txtrInstructions.setText("Instructions");
		txtrInstructions.setBounds(37, 353, 360, 45);
		add(txtrInstructions);

	}
	
	public void display()
	{
		GUI_Main.replacePanel(this);
	}
	
	private class AddListener implements ActionListener{
		public void actionPerformed(ActionEvent event){
			
			try
			{
			String prescription = txtrPrescription.getText();
			String labwork = txtrLabWork.getText();
			String followup = txtrFollowUp.getText();
			String other = txtrInstructions.getText();
			
			Orders order = new Orders( prescription , labwork, followup, other);
			GUI_Main.tscreen.setOrders(order);
			System.out.println(order.toString());
			}
			catch(NullPointerException e)
			{
				JOptionPane.showMessageDialog(null, "Human: Your data fields are not filled. \nProgrammer:"  +e.toString()); 
			}
		}
	}

}
